import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wch/constant/event_bus_global.dart';
import 'package:wch/native/net_business.dart';
import 'package:wch/page/data_report.dart';
import 'package:wch/widget/common_widget.dart';

import '../constant/resource_constant.dart';
import '../model/report_list_entity.dart';
import '../utils/log_utils.dart';
import '../widget/padding_widget.dart';

class EEGListPage extends StatefulWidget {
  const EEGListPage({super.key});

  @override
  State<EEGListPage> createState() => _EEGListPageState();
}

class _EEGListPageState extends State<EEGListPage> {

  FocusNode focusNode = FocusNode();

  TextEditingController controller = TextEditingController();

  @override
  void initState() {
    super.initState();
    controller.addListener(() {});
  }

  @override
  Widget build(BuildContext context) {
    return CommonScaffold(title: '脑电报告', body: Container(
      color: Color(0xFFF8F9FB),
      child: Container(
        child: Column(
          children: [
            Container(
              height: 36.h,
              margin: EdgeInsets.only(left: 15.w, right: 15.w, top: 15.h),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(17.5.h)),
                  border: Border.all(color: themeColor, width: 0.5.w)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  HorPadding(15.w),
                  Image.asset(
                    searchUserIcon,
                    width: 14,
                    height: 14,
                  ),
                  HorPadding(11.w),
                  Container(
                    width: ScreenUtil().screenWidth-120.w,
                    alignment: Alignment.centerLeft,
                    child: CupertinoTextField(
                      onSubmitted: (text) {
                        focusNode.unfocus();
                        SearchWords words = SearchWords(words: controller.text);
                        globalEventBus.fire(words);
                      },
                      focusNode: focusNode,
                      controller: controller,
                      textAlignVertical: TextAlignVertical.center,
                      decoration:
                      const BoxDecoration(color: Colors.transparent),
                      placeholder: '姓名、手机号码…',
                      placeholderStyle:
                      TextStyle(fontSize: 13, color: F1TextColor),
                      style: TextStyle(fontSize: 13.w, color: F1TextColor),
                      maxLines: 1,
                      maxLength: 11,

                    ),
                  )
                ],
              ),
            ),
            VerPadding(12.h),
            Expanded(child: DataReportPage(searchWords: controller.text,)),
          ],
        ),
      )
    ));
  }

  List<String> _searchUser(String searchWord) {
    LogUtils.log('searchWord=$searchWord');
    List<String> all = [];

    // if (searchWord == '') {
    //   for (int i = 0; i < oldUsers.length; i++) {
    //     all.add(oldUsers[i]);
    //   }
    //   return all;
    // }
    //
    // for (int i = 0; i < oldUsers.length; i++) {
    //   if (oldUsers[i].contains(searchWord)) {
    //     all.add(oldUsers[i]);
    //   }
    // }
    return all;
  }
}

class SearchWords {
  final String words;

  SearchWords({required this.words});
}
